<template>
  <div style="padding: 10px">
    <div style="">
      <el-input placeholder="请输入关键字" v-model="pagination.queryString" style="width: 20%;" ></el-input>
      <el-button style="background-color: #0066ff;border-color: #0066ff;margin-left: 5px"
                 type="primary" size="medium" @click="findSearchPage()">查询</el-button>
    </div>
    <div>
      <el-table
          :data="tableData"
          stripe
          style="width: 100%;margin-top: 10px">
        <el-table-column
            prop="id"
            label="id"
        >
        </el-table-column>
        <el-table-column
            prop="authorId"
            label="用户id"
        >
        </el-table-column>
        <el-table-column
            prop="account"
            label="用户名"
        >
        </el-table-column>
        <el-table-column
            prop="content"
            label="评论"
        >
        </el-table-column>
        <el-table-column
            prop="createTime"
            sortable
            label="创建时间">
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <!--            <el-button
                            size="mini"
                            type="primary"
                            @click="handleEdit(scope.$index, scope.row)">编辑</el-button>-->
            <el-popconfirm
                title="确定删除吗？"
                @confirm="handleDelete(scope.row.id)"
            >

              <el-button
                  style="margin-left: 4px"
                  slot="reference"
                  size="mini"
                  type="danger"
                  >删除</el-button>
            </el-popconfirm>

          </template>
        </el-table-column>
      </el-table>
    </div>
    <div>
      <el-pagination
          style="margin-top: 10px"
          background
          @current-change="handleCurrentChange"
          :current-page="pagination.currentPage"
          :page-size="pagination.pageSize"
          layout="total, prev, pager, next, jumper"
          :total="pagination.total">
      </el-pagination>
    </div>

  </div>
</template>

<script>


import {deleteUserComment, getAllUseComment} from "@/api/comment";

export default {
  name: "commentManagement",
  data() {
    return {
      tableData:[],
      pagination: {
        currentPage: 1,
        pageSize:10,
        total:0,
        queryString:null
      },
    }
  },
  methods:{
    findPage() {
      getAllUseComment(this.pagination).then((res)=>{
        if(res.data.data){
          this.tableData = res.data.data.list;
          this.pagination.total = res.data.data.total;
        }else{
          this.$message("系统错误")
        }
      }).catch((err)=>{
        this.$message("系统错误")
      })
    },
    findSearchPage(){
      this.pagination.currentPage = 1;
      this.findPage();
    },
    handleDelete(id) {
      deleteUserComment(id).then((res)=>{
        if(res.data.success === true){
          this.findPage()
          this.$message("删除成功")
        }else{
          this.$message("系统错误")
        }
      }).catch((err)=>{
        this.$message("系统错误")
      })
    },
    handleCurrentChange(currentPage) {
      this.pagination.currentPage = currentPage;
      this.findPage();
    }
  },
  created() {
    this.findPage()
  }
}
</script>

<style scoped>

</style>
